package tdh.xt.conditional;

import lombok.SneakyThrows;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import tdh.xt.common.utils.SourceUtil;

/*
* @Package tdh.xt.conditional
* @Description 用于判断是否注入Hibernate相关Bean的类
* @Author RicarAN
* @Date 2021/6/15 15:56
* @Copyright (c) 2021,南京通达海科技股份有限公司 All Rights Reserved.
* @Version 1.0
* Modification History:
* Date                  Author      Version     Description
* ------------------------------------------------------------------
* 2021/6/15 15:56       RicarAN      1.0        用于判断是否注入Hibernate相关Bean的类
*
*/
public class HibernateCondition implements Condition {

    /*
     * @description 是否注入Hibernate相关Bean
     * @param context
     * @param metadata
     * @return boolean 返回true则注入，反之不注入
     * @author RicarAN
     * @version 1.0
     * @date 2021/6/15 15:57
     */
    @SneakyThrows
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String ormName = SourceUtil.getPropertyValue("db/db.properties", "ormName");
        return StringUtils.isEmpty(ormName) || ormName.contains("hibernate");
    }
}
